package cn.smbms.controller;

import cn.smbms.pojo.Bill;
import cn.smbms.service.bill.BillService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/Bill")
public class BillController {

    @Resource
    private BillService billService;


    @RequestMapping(value = "billlist.html",method = RequestMethod.GET)
    public String getBillList(Model model,@RequestParam(value = "productName",required = false)String productName,
                              @RequestParam(value = "providerId",required = false)Integer providerId,
                              @RequestParam(value = "isPayment",required = false)Integer isPayment ){
        List<Bill>list=null;
        if(productName==null){
            productName="";
        }else {
            productName="%"+productName+"%";
        }
        if(providerId==null){
            providerId=null;
        }
        if(isPayment==null){
            isPayment=null;
        }
        Bill bill=new Bill();
        bill.setProductName(productName);
        bill.setProviderId(providerId);
        bill.setIsPayment(isPayment);
       list=billService.getBillList(bill);
        model.addAttribute("billList",list);
        return "billlist";
    }



    @RequestMapping(value = "billView.html",method = RequestMethod.POST)
    public String billView(){
        return "billview";
    }

}
